package com.example.wnn;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;

import com.alipay.api.FileItem;
import java.util.Base64;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AlipayFundTransToaccountTransfer {

    public static void main(String[] args) throws AlipayApiException {
//        // 初始化SDK
//        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
//        // 构造请求参数以调用接口
//        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
//        AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();
//        // 设置收款方账户
//        model.setPayeeAccount("18310519571");
//        // 设置收款方真实姓名（最长支持100个英文/50个汉字）
//        model.setPayeeRealName("刘宇辉");
//        // 设置收款方账户类型
//        model.setPayeeType("ALIPAY_LOGONID");
//        // 设置转账金额
//        model.setAmount("0.2");
//        // 设置转账备注（支持200个英文/100个汉字）
//        model.setRemark("佣金");
//        // 设置商户转账唯一订单号
//        model.setOutBizNo(UUID.randomUUID().toString().replace("-",""));
//        // 设置付款方姓名（最长支持100个英文/50个汉字）
//        model.setPayerShowName("一鸣置换超市");
//        request.setBizModel(model);
//        AlipayFundTransToaccountTransferResponse response = alipayClient.certificateExecute(request);
//        System.out.println(response.getBody());
//        if (response.isSuccess()) {
//            System.out.println("调用成功");
//        } else {
//            System.out.println("调用失败");
//            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
//            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
//            // System.out.println(diagnosisUrl);
//        }
    }

    private static AlipayConfig getAlipayConfig() {
        String privateKey  = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCUYOhHum9kZbqbau2x1WV5we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baXnXrn+Q+4aqrjbNFEpDVqemKrrp/DX678QUX93LtecHDwK0R2b5mw3f9FU9c2u7lFR+v7IpeImMsxJP0pc3Tj3qBxW7mw4qDGiYawNfns71xaj5AoGAOr4OaKg6HV/WKvS9/Gq321156l4bgSPgc0vybD6ydeZqrYJEaBH6i+2DPL7aijmv03yY8bifCCp/fFrwcKonc6xaJD8BOFq2Mj1WV6b1C+pr+2x+ycXhmUR4vPuJzer9TDZDRLWwJ63u/JPkVM31uioW1YiRCeRZKDRePztTgrUCgYA89E9/ZbrEWmg/WlRUqJzzSTI3LeFd0CZaoEXMCkY2At8/YnyR3IyORyLWPuqxNhDBd/UngaOGKxIdXzqB+/3jWJFWNwn3LVR15ZfFm7eqE1KvbwrGUj1EsA1M1aAavr1oc5iWPbyAPBmQfN8nwxgn1GXx+58wqAK/k5OXhX2JVw==";
      //  String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlGDoR7pvZGW6m2rtsdVlecHvgJ1zZ1wK6XptPKv+CSTwbMNxpVgTJUmQ9lf9QxDgTq5v9n8K9PcW+hk4Qp3HBVY4CCbU4QOmczmWRt3z6TM4zwkPCaz1ZDTYYKRaWg3rCP41bkQ66AIBpQsyqyfKRkTrWHL6giBsgQxOXc7IAWZ/GLoLUj+sm+N/5Zw882FC78z0cL3bog1ts8o3HDwKjwEBGH2XDFnujGEkZfoKT4onFLLATwpwHNBR0EiDC4rMjt7WmlWFoSykIpPXVjS3SzQlwo1qe1gJ1+e6yqK76W0/4hU1MwcB3CzAHQRQ1YxQ56keRtdbKYAmnGqGxZd72wIDAQAB";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        //alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
        alipayConfig.setAppId("2021004143660847");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
       // alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");

        String appCertPath ="/Users/wenzheng/Desktop/alicrt/appCertPublicKey_2021004143660847.crt";
        //设置应用公钥证书路径
        alipayConfig.setAppCertPath(appCertPath);
        //设置支付宝公钥证书路径
        String alipayPublicCertPath ="/Users/wenzheng/Desktop/alicrt/alipayCertPublicKey_RSA2.crt";
        alipayConfig.setAlipayPublicCertPath(alipayPublicCertPath);
        //设置支付宝根证书路径
        String rootCertPath ="/Users/wenzheng/Desktop/alicrt/alipayRootCert.crt";
        alipayConfig.setRootCertPath(rootCertPath);
        return alipayConfig;
    }
}